package com.riteny.oauth.ui;

import org.springframework.security.oauth2.provider.AuthorizationRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author Riteny
 * 2021/5/8  14:58
 */
@Controller
@RequestMapping("/user")
@SessionAttributes("authorizationRequest")
public class CustomOauthUIController {

    @GetMapping("/login")
    private String login() {
        return "login";
    }

    @GetMapping("/authorize")
    public ModelAndView getAccessConfirmation(Map<String, Object> model, HttpServletRequest request) throws Exception {

        AuthorizationRequest authorizationRequest = (AuthorizationRequest) model.get("authorizationRequest");

        ModelAndView view = new ModelAndView();
        view.setViewName("authroity");

        view.addObject("clientId", authorizationRequest.getClientId());

        view.addObject("scopes", authorizationRequest.getScope());

        return view;
    }
}
